//
//  AdressViewDetailVC.m
//  智慧小区
//
//  Created by 高永杨 on 2017/3/18.
//  Copyright © 2017年 zhongchuang. All rights reserved.
//

#import "AdressViewDetailVC.h"
#import "ChooseLocationView.h"
#import "CitiesDataTool.h"
#import "AdressDetailViewCell.h"
#import "BaseCell.h"
#import "TextFieldVC.h"
@interface AdressViewDetailVC ()<UIGestureRecognizerDelegate,UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) ChooseLocationView *chooseLocationView;
@property (nonatomic,strong) UIView  *cover;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
/**<#参数意思#>*/
@property(nonatomic,strong)NSMutableArray *nameArr;
/**<#参数意思#>*/
@property(nonatomic,strong)NSMutableArray *dataArr;
/**<#参数意思#>*/
@property(nonatomic,strong)NSMutableArray *typeArr;
@end

@implementation AdressViewDetailVC
static NSString *AdressDetailID = @"AdressDetailID";
-(NSMutableArray *)nameArr
{
    if (!_nameArr) {
        _nameArr = [NSMutableArray arrayWithObjects:@"收货人:",@"联系方式:",@"所在地区:",@"详细地址:", nil];
    }
    return _nameArr;
}

-(NSMutableArray *)dataArr
{
    if (!_dataArr) {
        _dataArr = [NSMutableArray arrayWithObjects:@"1",@"2",@"3",@"4", nil];
    }
    return _dataArr;
}

- (void)registerCell
{
  
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([TextFieldVC class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([TextFieldVC class])];
   [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([AdressDetailViewCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([AdressDetailViewCell class])];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.typeArr = [NSMutableArray arrayWithObjects:@"AdressDetailViewCell",@"AdressDetailViewCell",@"AdressDetailViewCell",@"TextFieldVC",nil];
    [[CitiesDataTool sharedManager] requestGetData];
    [self.view addSubview:self.cover];
//    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([AdressDetailViewCell class]) bundle:nil] forCellReuseIdentifier:AdressDetailID];
    [self registerCell];
    // Do any additional setup after loading the view from its nib.
    self.navigationItem.title = @"编辑收货人";
    [self setNav:self];
}
-(void)goBack
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    BaseCell *cell;
    NSString *cellIdentifier;
    cellIdentifier = self.typeArr[indexPath.row];
    cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
    [cell sendStr:self.nameArr[indexPath.row] andStr:self.dataArr[indexPath.row]];
    if (indexPath.row == 0) {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    return cell;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.nameArr.count;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.row) {
        case 0:
            break;
        case 1:
            
            break;
        case 2:
            self.cover.hidden = !self.cover.hidden;
            self.chooseLocationView.hidden = self.cover.hidden;
            break;
        default:
            break;
    }

}












- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    
    CGPoint point = [gestureRecognizer locationInView:gestureRecognizer.view];
    if (CGRectContainsPoint(_chooseLocationView.frame, point)){
        return NO;
    }
    return YES;
}
- (IBAction)saVeAdress:(UIButton *)sender {
    NSDictionary *dict = @{@"opt":@"9",@"token":@"fsfd",@"name":@"9",@"token":@"fsfd",@"opt":@"9",@"token":@"fsfd",@"opt":@"9",@"token":@"fsfd"};
    
//    [AFHTTPSessionManager manager] POST:<#(nonnull NSString *)#> parameters:<#(nullable id)#> progress:<#^(NSProgress * _Nonnull uploadProgress)uploadProgress#> success:<#^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject)success#> failure:<#^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error)failure#>
}






- (void)tapCover:(UITapGestureRecognizer *)tap{
    
    if (_chooseLocationView.chooseFinish) {
        _chooseLocationView.chooseFinish();
    }
}

- (ChooseLocationView *)chooseLocationView{
    
    if (!_chooseLocationView) {
        _chooseLocationView = [[ChooseLocationView alloc]initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height - 350, [UIScreen mainScreen].bounds.size.width, 350)];
        
    }
    return _chooseLocationView;
}

- (UIView *)cover{
    
    if (!_cover) {
        _cover = [[UIView alloc]initWithFrame:[UIScreen mainScreen].bounds];
        _cover.backgroundColor = [UIColor colorWithWhite:0 alpha:0.2];
        [_cover addSubview:self.chooseLocationView];
        __weak typeof (self) weakSelf = self;
        _chooseLocationView.chooseFinish = ^{
            [UIView animateWithDuration:0.25 animations:^{
                //                [weakSelf.cityBut setTitle:weakSelf.chooseLocationView.address forState:UIControlStateNormal];
                if (!weakSelf.chooseLocationView.address) return;
                [weakSelf.dataArr replaceObjectAtIndex:2 withObject:weakSelf.chooseLocationView.address];
                NSIndexPath *indexPath = [NSIndexPath indexPathForRow:2 inSection:0];
                NSArray *indexPathArr = @[indexPath];
                [weakSelf.tableView reloadRowsAtIndexPaths:indexPathArr withRowAnimation:UITableViewRowAnimationAutomatic];
                weakSelf.view.transform = CGAffineTransformIdentity;
                weakSelf.cover.hidden = YES;
            }];
        };
        UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapCover:)];
        [_cover addGestureRecognizer:tap];
        tap.delegate = self;
        _cover.hidden = YES;
    }
    return _cover;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
